<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Category;
use Carbon\Carbon;
use \Cache;

class CategoryController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function list(Request $request)
    {
        $this->validate($request, [
            'type' => 'nullable|numeric',//分类id
            'parent_id' => 'nullable|numeric',//父类id
        ]);

        $banner = Category::when($request->get('type'),function ($query){
                return $query->where('type', request('type'));
            })
            ->when($request->get('parent_id'),function ($query){
                return $query->where('parent_id', request('parent_id'));
            })
            ->orderBy('order')
            ->orderBy('created_at')
            ->get();

        return $this->successReturn($banner);
    }


}
